<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Chonmau_model extends CI_Model
{
	function __construct() 
	{
		parent::__construct();
	}
	
	public function initialise($lang)
    {
		$this->lang = $lang;
    }
	
	function getCategory($table,$col_sort='nb_level',$sort='ASC')
	{
		$this->db->select('catid, catname_'.$this->lang.' as catname, lb_image');
		$this->db->order_by($col_sort,$sort);
		$this->db->where('bl_active',1);
		return $this->db->get($table)->result();
	}
	
	function save($tbl, $data, $name='', $id=0)
	{
		if($name)
		{
			$this->db->where($name, $id) ;
			if($this->db->update($tbl, $data))
				return $id ;
			else return false;
		}
		else
		{
			if($this->db->insert($tbl,$data))
				return $this->db->insert_id();
			else return false;
		}
	}
	
	function getId($id,$table){
		$this->db->where('pro_id',$id);	
		return $this->db->get($table)->row();
	}
	
	function getAllCat($table,$cat_id){
		$this->db->where('bl_active',1);
		$this->db->where('catid',$cat_id);
		$this->db->order_by('nb_order','ASC');
		return $this->db->get($table)->result();
	}
}
?>
